home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_q_t / trem.zip / WRITE.C < prev   
Text File  |  1991-05-11  |  4KB  |  136 lines

  1. /************************************************************************
  2.  *
  3.  *    Copyright (c) 1991 Microsoft Corporation.  All Rights Reserved.
  4.  *
  5.  *-----------------------------------------------------------------------
  6.  *
  7.  *     Project:  Windows Terminal Example
  8.  *
  9.  *      Module:  write.c
  10.  *
  11.  *      Author:  Bryan A. Woodruff (baw)
  12.  *
  13.  *
  14.  *     Remarks:  This controls the writing of characters to the "screen".
  15.  *
  16.  *   Revisions:  
  17.  *     01.00.000  5/ 9/91 baw   Wrote it.
  18.  *
  19.  ************************************************************************/
  20.  
  21. #include "terminal.h"
  22.  
  23. /************************************************************************
  24.  *  BOOL WriteTerminalByte( HWND hWnd, BYTE bIn )
  25.  *
  26.  *  Description: 
  27.  *     Writes character to terminal screen.  Nothing fancy - just
  28.  *     straight TTY.
  29.  *
  30.  *  Comments:
  31.  *      5/ 9/91  baw  Wrote it.
  32.  *
  33.  ************************************************************************/
  34.  
  35. BOOL WriteTerminalByte( HWND hWnd, BYTE bIn )
  36. {
  37.    LOCALHANDLE  hTermInfo ;
  38.    NPTERMINFO   npTermInfo ;
  39.    RECT         rect ;
  40.  
  41.    hTermInfo = GetWindowWord( hWnd, GWW_TERMINFO ) ;
  42.    if (NULL == (npTermInfo = (NPTERMINFO) LocalLock( hTermInfo )))
  43.       return ( FALSE ) ;
  44.  
  45.    switch (bIn)
  46.    {
  47.       case ASCII_BEL:
  48.          // Bell
  49.          MessageBeep( 0 ) ;
  50.          break ;
  51.  
  52.       case ASCII_BS:
  53.          // Backspace
  54.          if (npTermInfo -> nColumn > 0)
  55.             npTermInfo -> nColumn -- ;
  56.          MoveTerminalCursor( hWnd ) ;
  57.          break ;
  58.  
  59.       case ASCII_CR:
  60.          // Carriage return
  61.          npTermInfo -> nColumn = 0 ;
  62.          MoveTerminalCursor( hWnd ) ;
  63.          if (!npTermInfo -> fNewLine)
  64.             break;
  65.  
  66.          // fall through
  67.  
  68.       case ASCII_LF:
  69.          // Line feed
  70.          if (npTermInfo -> nRow++ == MAXROWS - 1)
  71.          {
  72.             _fmemmove( (LPSTR) (npTermInfo -> abScreen),
  73.                        (LPSTR) (npTermInfo -> abScreen + MAXCOLS),
  74.                        (MAXROWS - 1) * MAXCOLS ) ;
  75.             _fmemset( (LPSTR) (npTermInfo -> abScreen + (MAXROWS - 1) * MAXCOLS),
  76.                       ' ', MAXCOLS ) ;
  77.             InvalidateRect( hWnd, NULL, FALSE ) ;
  78.             npTermInfo -> nRow-- ;
  79.          }
  80.          MoveTerminalCursor( hWnd ) ;
  81.          break ;
  82.  
  83.       default:
  84.          *(LPSTR)(npTermInfo -> abScreen + npTermInfo -> nRow * MAXCOLS +
  85.                   npTermInfo -> nColumn) = bIn ;
  86.          rect.left = (npTermInfo -> nColumn * npTermInfo -> xChar) -
  87.                      npTermInfo -> xOffset ;
  88.          rect.right = rect.left + npTermInfo -> xChar ;
  89.          rect.top = (npTermInfo -> nRow * npTermInfo -> yChar) -
  90.                     npTermInfo -> yOffset ;
  91.          rect.bottom = rect.top + npTermInfo -> yChar ;
  92.          InvalidateRect( hWnd, &rect, FALSE ) ;
  93.  
  94.          // Line wrap
  95.          if (npTermInfo -> nColumn < MAXCOLS - 1)
  96.             npTermInfo -> nColumn++ ;
  97.          else if (npTermInfo -> fAutoWrap)
  98.          {
  99.             WriteTerminalByte( hWnd, ASCII_CR ) ;
  100.             WriteTerminalByte( hWnd, ASCII_LF ) ;
  101.          }
  102.          break;
  103.    }     
  104.    LocalUnlock( hTermInfo ) ;
  105.    return ( TRUE ) ;
  106.  
  107. } /* end of WriteTerminalByte() */
  108.  
  109. /************************************************************************
  110.  *  BOOL WriteTerminalBlock( HWND hWnd, LPSTR lpBlock, int nLength )
  111.  *
  112.  *  Description: 
  113.  *     Writes a block to the terminal screen.
  114.  *     Calls WriteTerminalByte().
  115.  *
  116.  *  Comments:
  117.  *      5/10/91  baw  Wrote it.
  118.  *
  119.  ************************************************************************/
  120.  
  121. BOOL WriteTerminalBlock( HWND hWnd, LPSTR lpBlock, int nLength )
  122. {
  123.    int  i ;
  124.  
  125.    for (i = 0; i < nLength; i++)
  126.       WriteTerminalByte( hWnd, lpBlock[i] ) ;
  127.  
  128.    return ( TRUE ) ;
  129.  
  130. } /* end of WriteTerminalBlock() */
  131.  
  132. /************************************************************************
  133.  * End of File: write.c
  134.  ************************************************************************/
  135.  
  136.